package com.amado.course40Reflect;

/**
 * 静态代理
 * Created by Administrator on 2018/8/4.
 */
public class S04StaticProxyMethod {

	public static void main(String[] args) {
		User user = new UserProxy();
		user.getUser(1);
	}

	static class UserImpl implements User {
		@Override
		public String getUser(long id) {
			// 相当于 new Date().getTime();
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("do something");
			return id + "name";
		}
	}

	static class UserProxy implements User {
		User user = new UserProxyTwo();
		@Override
		public String getUser(long id) {
			long startTime = System.currentTimeMillis();
			String a = user.getUser(1);
			long endTime = System.currentTimeMillis();
			System.out.println("耗时MS " + (endTime - startTime));
			return a;
		}
	}
	static class UserProxyTwo implements User {
		User user = new UserImpl();
		@Override
		public String getUser(long id) {
			String a = user.getUser(1);
			System.out.println("返回值"+a);
			return a;
		}
	}
}
